﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model.Query;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL;
using HZ.Supervise.DAL;


public partial class Hospital_HospitalHighPricedDrugs : BasePage
{
    public Hospital_HospitalHighPricedDrugs()
    { }
    int totalrecord = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["query"] = URLUtil.GetSuperviseQueryFromURL(Request);
            BindData();
        }
    }

    protected void btnQuery_Click(object sender, EventArgs e)
    {
        this.AspNetPager1.CurrentPageIndex = 1;
        BindData();
    }
    private void BindData()
    {
        HZ.Supervise.Model.Query.ProcureCatalog QProcureCatalog = new HZ.Supervise.Model.Query.ProcureCatalog();
        QProcureCatalog.ProductName = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtProductName.Text.Trim());
        QProcureCatalog.MedicineModelName = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtMedicineModelName.Text.Trim());
        QProcureCatalog.Outlookc = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtOutlookc.Text.Trim());
        QProcureCatalog.CompanyName_SC = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtCompanyName_SC.Text.Trim());
        QProcureCatalog.CompanyName_TB = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtCompanyName_TB.Text.Trim());
        QProcureCatalog.SortFields = "ProductName asc,MedicineModelName asc,Outlookc asc";
        HZ.Supervise.IBLL.IBLL_ProcureCatalog iProcureCatalog = HZ.Supervise.BLLFactory.IBLL_ProcureCatalog();
        this.gvwInfo.DataSource = iProcureCatalog.GetIsPreciousProcureCatalog(QProcureCatalog, true, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out totalrecord);

        AspNetPager1.RecordCount = totalrecord;
        this.gvwInfo.DataBind();
    }
    protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
    {
        BindData();
    }

    protected void gvwInfo_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DierectByDtail")
        {
            //设置分组查询字段GroupSelectField
            if (ShowColumns.ShowColumn == null)
            {
                ShowColumns.ShowColumn = new ShowColumns();
                ShowColumns.ShowColumn.GroupFields = GroupFields.PurchaseCountTotal | GroupFields.PriceAvg | GroupFields.PurchaseAmountTotal | GroupFields.DistributeCountTotal | GroupFields.DistributeRate | GroupFields.WareHouseCountTotal | GroupFields.WareHouseAmountTotal | GroupFields.WareHouseRate;
            }
            string sessionid = Guid.NewGuid().ToString();
            SuperviseQuery query = (SuperviseQuery)ViewState["query"];
            query.ProcureCatalogID = e.CommandArgument.ToString();
            Session[sessionid] = query;
            string url = System.Configuration.ConfigurationManager.AppSettings["HosComDrugs"];



            Response.Redirect(string.Format("{0}?sessionid={1}", url, sessionid));
        }
    }
    protected void btnExcel_Click(object sender, EventArgs e)
    {
        HZ.Supervise.Model.Query.ProcureCatalog QProcureCatalog = new HZ.Supervise.Model.Query.ProcureCatalog();
        QProcureCatalog.ProductName = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtProductName.Text.Trim());
        QProcureCatalog.MedicineModelName = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtMedicineModelName.Text.Trim());
        QProcureCatalog.Outlookc = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtOutlookc.Text.Trim());
        QProcureCatalog.CompanyName_SC = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtCompanyName_SC.Text.Trim());
        QProcureCatalog.CompanyName_TB = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtCompanyName_TB.Text.Trim());
        QProcureCatalog.SortFields = "ProductName asc,MedicineModelName asc,Outlookc asc";
        HZ.Supervise.IBLL.IBLL_ProcureCatalog iProcureCatalog = HZ.Supervise.BLLFactory.IBLL_ProcureCatalog();
        System.Data.DataTable dt = iProcureCatalog.GetIsPreciousProcureCatalog(QProcureCatalog, true, 0, 0, out totalrecord);

        ExportFile.Instance.ExportData(dt, gvwInfo, this.Page);
    }
}
